package com.rfid.afd.model;

import com.rfid.db.bean.Deleted;
import com.rfid.db.bean.Operation;
import com.rfid.db.bean.Rfid;
import com.rfid.util.DBManager;
import com.rfid.util.UserManager;
import com.rfid.util.Util;

import java.util.List;

public class DeleteModel extends BaseModel{

    public List<Rfid> getRfidsByBookName(String book) {
        return DBManager.queryRfidsByBookName(book);
    }

    public List<Rfid> getRemoteDeleteRfids() {
        return DBManager.queryRfidsByDeletedTable();
    }

    public void deleteRfids(List<Rfid> rfids) {
        if(rfids.size() == 0) {
            return;
        }
        for(Rfid rfid : rfids) {
            rfid.setDeleted(1);
            Deleted deleted = DBManager.queryDeleted(rfid.getUid());
            if(deleted != null) {
                DBManager.deleteDeleted(deleted);
            }
            Operation operation = new Operation();
            operation.setOperation(Operation.OPERATE_SHANGJIA);
            operation.setRfid(rfid.getId());
            operation.setDate(Util.getDateTime());
            operation.setUser(UserManager.getInstance().getLoginUser().getName());
            DBManager.insertOperation(operation);
        }
        DBManager.updateRfids(rfids);
    }
}
